#include <iostream>
using namespace std;

char * prefix(const char * const s1, const char * const s2)
{
  int len = strlen(s1);

  char *pNewString = new char[strlen(s1) + 1];

  int i = 0;
  for (; i < len; i++)
  {
    if (s1[i] == s2[i])
      pNewString[i] = s1[i];
    else
      break;
  }

  pNewString[i] = '\0'; // Set a null terminator

  return pNewString;
}

int main()
{
  char *s1;
  char *s2;

  cout << "Enter s1: ";
  cin >> s1;

  cout << "Enter s2: ";
  cin >> s2;

  char *s3 = prefix(s1, s2);
  if (strlen(s3) == 0)
    cout << "No common prefix" << endl;
  else
    cout << "The common prefix is " << prefix(s1, s2) << endl;

  return 0;
}
